package com.vnp.cooking;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.graphics.Typeface;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Display;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import com.vnp.cooking.UIcontrols.OnSwipeTouchListener;
import com.vnp.cooking.adapter.DialogItemCity;
import com.vnp.cooking.bean.ObjCity;
import com.vnp.cooking.httpclient.HttpClientHelper;
import com.vnp.cooking.httpclient.MyJsonHttpResponseHandler;
import com.vnp.cooking.utils.KeyboardHelper;
import com.vnp.cooking.utils.PreferenceHelper;
import com.vnp.cooking.utils.UsernameValidator;
import com.vnp.cooking.utils.Utils;

public class ChinhsuaThongtinActivity extends Activity implements OnClickListener, OnTouchListener{
	
	PreferenceHelper preferenceHelper;
	ImageButton imgBack;
	
	Button btnSaveAll;
	Button btnEditUrl, btnPostUrl, btnEditInfo, btnPostInfo;
	TextView txtTitleName, titleUrlCanhan, titleThongbao;
	EditText edt_url, edt_ten, edt_about;
	TextView edt_email, edt_ngaysinh, edt_gioitinh, edt_thanhpho;
	LinearLayout main;
	boolean isPostUrl = false;
	ViewGroup edtViewGroup;
	
	// gioi tinh
	final String[] items = {"Nam", "Nữ"};
	String gender;
	// ngay sinh
	static final int DATE_DIALOG_ID = 0;
	private int pYear;
	private int pMonth;
	private int pDay;
	// progress bar
//	ProgressBar progressBarUrl, progressBarInfo;
	
	//settings
	int notification_like;
	int notification_comment;
	
	ImageButton btnSettingsLike, btnSettingSComment;
	
	Dialog dT, dArlert, dEmail;
	ArrayList<ObjCity> objCities = new ArrayList<ObjCity>();
	
	boolean isProcessing = false;
	Handler mHandler = new Handler();
	
	HashMap<Integer, String> mapCity = new HashMap<Integer, String>();
	
	private UsernameValidator usernameValidator;
	ProgressDialog progressDialog;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_chinhsua_thongtin);
		preferenceHelper = new PreferenceHelper(this);
		
		notification_comment = preferenceHelper.getSettingComment();
		notification_like = preferenceHelper.getSettingLike();
		
		Log.i("DATA", "LIKE AND COMMENT: "+notification_comment +" "+notification_like);
		
		
		main = (LinearLayout) findViewById(R.id.main_layout);
		KeyboardHelper.setupUI(this, main);
		
		
		titleUrlCanhan = (TextView) findViewById(R.id.title_url_canhan);
		titleThongbao = (TextView) findViewById(R.id.title_thongbao);
		
		imgBack = (ImageButton) findViewById(R.id.btn_back);
		txtTitleName = (TextView) findViewById(R.id.txt_my_name);
		btnPostInfo = (Button) findViewById(R.id.btn_post_thongtin);
		btnPostUrl = (Button) findViewById(R.id.btn_post_url);
		
		btnSaveAll = (Button) findViewById(R.id.btn_save_all);
		
		// khai bao progress
//		progressBarUrl = (ProgressBar) findViewById(R.id.probgressbar_url);
//		progressBarInfo = (ProgressBar) findViewById(R.id.probgressbar_info);
		
		
		// khai bao cac edit thong tin
		edt_url = (EditText) findViewById(R.id.edt_url);
		edt_ten = (EditText) findViewById(R.id.edt_ten);
		edt_email = (TextView) findViewById(R.id.edt_email);
		edt_ngaysinh = (TextView) findViewById(R.id.edt_ngaysinh);
		edt_gioitinh = (TextView) findViewById(R.id.edt_gioitinh);
		edt_thanhpho = (TextView) findViewById(R.id.edt_thanhpho);
		edt_about = (EditText) findViewById(R.id.edt_gioithieu_banthan);
		edtViewGroup = (ViewGroup) findViewById(R.id.edt_url_ll);
		
		// button setting
		btnSettingsLike = (ImageButton) findViewById(R.id.btn_open_noti_thich);
		btnSettingSComment = (ImageButton) findViewById(R.id.btn_open_noti_binhluan);
		
		setFont();
		init();
		initData();
		actionEdittext();
		
	}
	
	private void setFont() {
		txtTitleName.setTypeface(Utils.getTypefaceRegular(ChinhsuaThongtinActivity.this), Typeface.BOLD);
		btnSaveAll.setTypeface(Utils.getTypefaceRegular(ChinhsuaThongtinActivity.this));
		titleUrlCanhan.setTypeface(Utils.getTypefaceRegular(ChinhsuaThongtinActivity.this), Typeface.BOLD);
		titleThongbao.setTypeface(Utils.getTypefaceRegular(ChinhsuaThongtinActivity.this), Typeface.BOLD);
		edt_url.setTypeface(Utils.getTypefaceRegular(ChinhsuaThongtinActivity.this));
		edt_ten.setTypeface(Utils.getTypefaceRegular(ChinhsuaThongtinActivity.this));
		edt_email.setTypeface(Utils.getTypefaceRegular(ChinhsuaThongtinActivity.this));
		edt_ngaysinh.setTypeface(Utils.getTypefaceRegular(ChinhsuaThongtinActivity.this));
		edt_gioitinh.setTypeface(Utils.getTypefaceRegular(ChinhsuaThongtinActivity.this));
		edt_thanhpho.setTypeface(Utils.getTypefaceRegular(ChinhsuaThongtinActivity.this));
		edt_about.setTypeface(Utils.getTypefaceRegular(ChinhsuaThongtinActivity.this));
		
		
	}
	
	
	void init(){
		
		loadCacheDataCity();
		
		txtTitleName.setText(preferenceHelper.getUserInfoName());
		imgBack.setOnTouchListener(this);
		btnPostInfo.setOnClickListener(this);
		btnPostUrl.setOnClickListener(this);
		btnPostInfo.setEnabled(true);
		btnPostUrl.setEnabled(false);
		edt_gioitinh.setOnTouchListener(this);
		edt_ngaysinh.setOnTouchListener(this);
		edt_email.setOnTouchListener(this);
		edt_thanhpho.setOnTouchListener(this);
		btnSettingSComment.setOnTouchListener(this);
		btnSettingsLike.setOnTouchListener(this);
		
		btnSaveAll.setOnTouchListener(this);
		
		Log.i("DATA", "Settings comment: "+preferenceHelper.getSettingComment());
		Log.i("DATA", "Settings like: "+preferenceHelper.getSettingLike());
		if (preferenceHelper.getSettingComment() == 0) {
			btnSettingSComment.setImageResource(R.drawable.off);
		} else {
			btnSettingSComment.setImageResource(R.drawable.on);
		}
		
		if (preferenceHelper.getSettingLike() == 0) {
			btnSettingsLike.setImageResource(R.drawable.off);
		} else {
			btnSettingsLike.setImageResource(R.drawable.on);
		}
		
		String[] result = preferenceHelper.getUserBirthl().split("-");
		try {
			pYear = Integer.parseInt(result[0]);
		} catch (Exception e) { }

		try {
			pMonth = Integer.parseInt(result[1]);
		} catch (Exception e) { }

		try {
			pDay = Integer.parseInt(result[2]);
		} catch (Exception e) { }
		updateDisplay();
	}
	
	void initData() {
		edt_url.setText(preferenceHelper.getUsername());
		edt_url.setSelection(edt_url.getText().length());
		Log.i("DATA", "USERNAME  nhan duoc: "+preferenceHelper.getUsername());
		gender = preferenceHelper.getUserGender();
		edt_ten.setText(preferenceHelper.getUserInfoName());
		edt_email.setText(preferenceHelper.getUserEmail());
		edt_ngaysinh.setText(preferenceHelper.getUserBirthl());
		Log.i("DATA", preferenceHelper.getUserGender());
		if (preferenceHelper.getUserGender().equals("MALE")) {
			edt_gioitinh.setText("Nam");
		} else if (preferenceHelper.getUserGender().equals("FEMALE")) {
			edt_gioitinh.setText("Nữ");
		}
		
		// hien thi thanh pho
		Iterator myVeryOwnIterator = mapCity.keySet().iterator();
		while(myVeryOwnIterator.hasNext()) {
		    int key= (Integer) myVeryOwnIterator.next();
		    String value=(String)mapCity.get(key);
		    
		    if (key == preferenceHelper.getUserCity()) {
		    	edt_thanhpho.setText(""+value);
		    	preferenceHelper.setNameCity(value);
		    }
		}
		
		edt_about.setText(preferenceHelper.getUserAbout());
	}
	
	void actionEdittext() {
		edt_url.addTextChangedListener(new TextWatcher() {
			
			@Override
			public void onTextChanged(CharSequence s, int start, int before, int count) {

			}
			
			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
				
			}
			
			@Override
			public void afterTextChanged(Editable s) {
				btnPostUrl.setEnabled(true);
			}
		});
		
		edt_ten.addTextChangedListener(new TextWatcher() {
			
			@Override
			public void onTextChanged(CharSequence s, int start, int before, int count) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void afterTextChanged(Editable s) {
				
			}
		});
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_back:
			break;
			
		case R.id.btn_save_all:
			
			break;
		case R.id.btn_post_url:
//			progressBarUrl.setVisibility(View.VISIBLE);
//			btnPostUrl.setVisibility(View.GONE);
			if (edt_url.getText().toString().matches("")) {
//				progressBarUrl.setVisibility(View.GONE);
//				btnPostUrl.setVisibility(View.VISIBLE);
				Toast.makeText(ChinhsuaThongtinActivity.this, "URL không được rỗng!", Toast.LENGTH_SHORT).show();
			} else {
				boolean valid = UsernameValidator.validate(edt_url.getText().toString());
				if (valid) {
					postUrl();
				} else {
//					progressBarUrl.setVisibility(View.GONE);
//					btnPostUrl.setVisibility(View.VISIBLE);
					Toast.makeText(ChinhsuaThongtinActivity.this, "URL không hợp lệ!", Toast.LENGTH_SHORT).show();
				}
				
			}
			
			break;
		case R.id.btn_post_thongtin:
//			progressBarInfo.setVisibility(View.VISIBLE);
//			btnPostInfo.setVisibility(View.GONE);
			updateInfo();
			break;
		case R.id.edt_email:
			break;
		case R.id.edt_gioitinh:
			break;
		case R.id.edt_ngaysinh:
			break;
			
		case R.id.btn_open_noti_binhluan:
			
			break;
		case R.id.btn_open_noti_thich:
			
			break;
		case R.id.edt_thanhpho:
			break;
		default:
			break;
		}
	}
	
	
	// update url chinh suar
	public void postUrl() {
		HttpClientHelper httpClientHelper = new HttpClientHelper(new MyJsonHttpResponseHandler(){

			@Override
			public void onFailure(Throwable error) {
				btnPostUrl.setText("Cập nhật");
				super.onFailure(error);
			}

			@Override
			public void onSuccess(JSONObject re) {
				try {
					int status = re.getInt("status");
					if (status == 200) {
//						progressBarUrl.setVisibility(View.GONE);
//						btnPostUrl.setVisibility(View.VISIBLE);
						preferenceHelper.setUserName(edt_url.getText().toString());
						btnPostUrl.setEnabled(false);
						Toast.makeText(ChinhsuaThongtinActivity.this, "Cập nhật thành công!", Toast.LENGTH_SHORT).show();
					} else {
						Toast.makeText(ChinhsuaThongtinActivity.this, "Cập nhật thất bại!", Toast.LENGTH_SHORT).show();
					}
				} catch (JSONException e) {
					e.printStackTrace();
				}
				
			}
			
		});
		httpClientHelper.updateUrl(preferenceHelper.getID(), edt_url.getText().toString());
		
	}
	
	// cap nhat thong tin
	public void updateInfo() {
		isProcessing = true;
		HttpClientHelper httpClientHelper = new HttpClientHelper(new MyJsonHttpResponseHandler(){

			@Override
			public void onSuccess(JSONObject re) {
				try {
					int status = re.getInt("status");
					progressDialog.dismiss();
					switch (status) {
					case 200:
						isProcessing = false;
//						progressBarInfo.setVisibility(View.GONE);
//						btnPostInfo.setVisibility(View.VISIBLE);
						
						preferenceHelper.setUserInfoName(edt_ten.getText().toString());
						preferenceHelper.setUserBirth(edt_ngaysinh.getText().toString());
						if (edt_gioitinh.getText().toString().equals("Name")) {
							preferenceHelper.setUserGender("MALE");
						} else if (edt_gioitinh.getText().toString().equals("Nữ")) {
							preferenceHelper.setUserGender("FEMALE");
						}
						
						preferenceHelper.setUserAbout(edt_about.getText().toString());
						txtTitleName.setText(edt_ten.getText().toString());
						preferenceHelper.setSettingsComment(notification_comment);
						preferenceHelper.setSettingsLike(notification_like);
						
						preferenceHelper.setNameCity(edt_thanhpho.getText().toString());
						Log.i("DATA", "LIKE AND COMMENT: "+notification_comment +" "+notification_like);
						Toast.makeText(ChinhsuaThongtinActivity.this, "Cập nhật thành công.", Toast.LENGTH_SHORT).show();
						break;
					case 400:
						isProcessing = false;
						Toast.makeText(ChinhsuaThongtinActivity.this, "Dữ liệu không đúng.", Toast.LENGTH_SHORT).show();
						break;
					case 404:
						isProcessing = false;
						Toast.makeText(ChinhsuaThongtinActivity.this, "Không tìm thấy người dùng.", Toast.LENGTH_SHORT).show();
						break;

					default:
						break;
					}
				} catch (JSONException e) {
					e.printStackTrace();
				}
			}

			@Override
			public void onFailure(Throwable error) {
				super.onFailure(error);
				progressDialog.dismiss();
				Toast.makeText(ChinhsuaThongtinActivity.this, "Không thể kết nối với server.", Toast.LENGTH_SHORT).show();
			}
			
		});
		httpClientHelper.updateInfo(preferenceHelper.getID(), creatData());
	}
	
	public JSONObject creatData() {
		final JSONObject data = new JSONObject();
		/*data.put("dob", value);
		data.put("city_id", value);
		*/
		
		if (edt_url.getText().toString().matches("")){
			
		} else {
			try {
				data.put("username", edt_url.getText().toString());
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
		
		try {
			data.put("gender", gender);
		} catch (JSONException e1) {
			e1.printStackTrace();
		}
		try {
			data.put("name", edt_ten.getText().toString());
		} catch (JSONException e) {
			e.printStackTrace();
		}
		try {
			data.put("about", edt_about.getText().toString());
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
		try {
			data.put("dob", edt_ngaysinh.getText().toString());
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		try {
			data.put("city_id", preferenceHelper.getUserCity());
		} catch (JSONException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		try {
			data.put("notification_like", notification_like);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
		try {
			data.put("notification_comment", notification_comment);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return data;
		
	}
	
	// chonj gioi tinh
	void chooseGender() {
		AlertDialog.Builder builder3=new AlertDialog.Builder(ChinhsuaThongtinActivity.this);
		builder3.setTitle("Chọn giới tính").setItems(items, new DialogInterface.OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which) {
		  
//			  Toast.makeText(getApplicationContext(), "U clicked "+items[which], Toast.LENGTH_LONG).show();
				gender = items[which];
				if (gender.equals("Nam")) {
					gender = "MALE";
					edt_gioitinh.setText("Nam");
				} else if (gender.equals("Nữ")) {
					gender = "FEMALE";
					edt_gioitinh.setText("Nữ");
				}
				
				
			}
		  
		});

		 builder3.show();

	}
	
	
	/** Callback received when the user "picks" a date in the dialog */
	public DatePickerDialog.OnDateSetListener pDateSetListener = new DatePickerDialog.OnDateSetListener() {

		@Override
		public void onDateSet(DatePicker view, int year, int monthOfYear,
				int dayOfMonth) {
			// TODO Auto-generated method stub
			pYear = year;
			pMonth = monthOfYear+1;
			pDay = dayOfMonth;
			updateDisplay();

		}
	};
	
	/** Update date to edittext */
	private void updateDisplay() {
		edt_ngaysinh.setText(new StringBuilder().append(Utils.checkDigit(pDay)).append("-").append(Utils.checkDigit(pMonth)).append("-").append(pYear).append(""));
	}
	
	/** Creat new Dialog for date picker */
	@Override
	@Deprecated
	public Dialog onCreateDialog(int id) {
		// TODO Auto-generated method stub
		switch (id) {
		case DATE_DIALOG_ID:
			return new DatePickerDialog(ChinhsuaThongtinActivity.this, pDateSetListener, pYear, (pMonth-1), pDay);
		}
		return null;
	}
	
	void showDialogThanhpho(){
		dT = new Dialog(ChinhsuaThongtinActivity.this, R.style.DialogSlideAnimLeft);
		dT.requestWindowFeature(Window.FEATURE_NO_TITLE);
		dT.setContentView(R.layout.dialog_thanhpho);

		// khai bao cac thanh phan
		
		
		ListView listThanhpho = (ListView) dT
				.findViewById(R.id.dialog_list_thanhpho);
		final DialogItemCity adapter = new DialogItemCity(
				ChinhsuaThongtinActivity.this, objCities);
		listThanhpho.setAdapter(adapter);

		Display display = ((WindowManager) getSystemService(ChinhsuaThongtinActivity.WINDOW_SERVICE))
				.getDefaultDisplay();
		int width = display.getWidth();
		int height = display.getHeight();

		dT.getWindow().setLayout((6 * width) / 7,
				((3 * height) / 5));

		dT.setCanceledOnTouchOutside(true);
		dT.show();
		dT.getWindow().setBackgroundDrawable(new ColorDrawable(0));
		dT.getWindow().setGravity(Gravity.CENTER);

		
		listThanhpho.setOnItemClickListener(new OnItemClickListener() {
			

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int position,
					long arg3) {
				edt_thanhpho.setText(objCities.get(position).getName());
				preferenceHelper.setUserCity(objCities.get(position).getId());
				dT.dismiss();
			}
		});
		
	}
	
	
	void loadCacheDataCity() {
			String cache = preferenceHelper.getDataFilter();
			if(!cache.equals("")) {
				try {
					JSONObject response = new JSONObject(cache);
					parseData(response);
				} catch (Exception e) { }
			}
	}
	
	
	public void parseData(JSONObject re) {
		try {
			int status = re.getInt("status");
			if (status == 200) {
				JSONObject data = re.getJSONObject("data");
				JSONArray cities = data.getJSONArray("city");
				for (int i = 0; i < cities.length(); i++) {
					JSONObject city = cities.getJSONObject(i);
					ObjCity objCity = new ObjCity();
					objCity.setId(city.getInt("id"));
					objCity.setName(city.getString("name"));
					objCities.add(objCity);
					
					int key = city.getInt("id");
					String value = city.getString("name");
					mapCity.put(key, value);
				}
			} else {
				Toast.makeText(ChinhsuaThongtinActivity.this, "Không lấy được dữ liệu",  Toast.LENGTH_SHORT).show();
			}
		} catch (JSONException e) {
			e.printStackTrace();
			Toast.makeText(ChinhsuaThongtinActivity.this, "Không lấy được dữ liệu",  Toast.LENGTH_SHORT).show();
		}
	}
	
	// show dialog dang thuc hien 1 hanh dong noa do
	public void showDialogProcess() {
		dArlert = new Dialog(ChinhsuaThongtinActivity.this, R.style.DialogSlideAnimLeft);
		dArlert.requestWindowFeature(Window.FEATURE_NO_TITLE);
		dArlert.setContentView(R.layout.dialog_thoat_process);

		// khai bao cac thanh phan
		TextView txtArlert = (TextView) dArlert.findViewById(R.id.str_canhbao_thoat);
		Button btnThoat = (Button) dArlert.findViewById(R.id.btn_thoat);
		Button btnKoThoat = (Button) dArlert.findViewById(R.id.btn_ko_thoat);
		
		
		btnThoat.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				dArlert.dismiss();
				closeActivity();
			}
		});
		
		btnKoThoat.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				dArlert.dismiss();
			}
		});

		dArlert.setCanceledOnTouchOutside(true);
		dArlert.show();
		dArlert.getWindow().setBackgroundDrawable(new ColorDrawable(0));
		dArlert.getWindow().setGravity(Gravity.CENTER);

		
	}
	
	void showDialofArlertDontEditEmail() {
		dEmail = new Dialog(ChinhsuaThongtinActivity.this, R.style.DialogSlideAnimLeft);
		dEmail.requestWindowFeature(Window.FEATURE_NO_TITLE);
		dEmail.setContentView(R.layout.dialog_khong_sua_email);

		// khai bao cac thanh phan
		Button btnThoat = (Button) dEmail.findViewById(R.id.btn_thoat);
		
		
		btnThoat.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				dEmail.dismiss();
			}
		});
		

		dEmail.setCanceledOnTouchOutside(true);
		dEmail.show();
		dEmail.getWindow().setBackgroundDrawable(new ColorDrawable(0));
		dEmail.getWindow().setGravity(Gravity.CENTER);
	}

	
	void closeActivity(){
		finish();
		overridePendingTransition(R.anim.open_main, R.anim.close_next);
	}


	@Override
	public void onBackPressed() {
		closeActivity();
	}
	
	
	void checkUpdateInfoTrue() {
		if (edt_url.getText().toString().matches("")) {
			progressDialog.dismiss();
			Toast.makeText(ChinhsuaThongtinActivity.this, "URL không được rỗng!", Toast.LENGTH_SHORT).show();
		} else {
			boolean valid = UsernameValidator.validate(edt_url.getText().toString());
			if (valid) {
				if (edt_ten.getText().toString().matches("")) {
					progressDialog.dismiss();
					Toast.makeText(ChinhsuaThongtinActivity.this, "Tên không được rỗng!", Toast.LENGTH_SHORT).show();
				} else {
					updateInfo();
					/*boolean validTen = UsernameValidator.validate(edt_ten.getText().toString());
					if (validTen) {
						updateInfo();
					} else {
						progressDialog.dismiss();
						Toast.makeText(ChinhsuaThongtinActivity.this, "Tên không hợp lệ!", Toast.LENGTH_SHORT).show();
					}*/
					
				}
				
			} else {
				progressDialog.dismiss();
				Toast.makeText(ChinhsuaThongtinActivity.this, "URL không hợp lệ!", Toast.LENGTH_SHORT).show();
			}
			
		}
	}


	@Override
	public boolean onTouch(View v, MotionEvent event) {
		switch (v.getId()) {
		case R.id.btn_open_noti_binhluan:
			if (event.getAction() == MotionEvent.ACTION_UP){
				if (notification_comment == 0) {
					notification_comment = 1;
					btnSettingSComment.setImageResource(R.drawable.on);
				} else {
					notification_comment = 0;
					btnSettingSComment.setImageResource(R.drawable.off);
				}
			}
			break;
		case R.id.btn_open_noti_thich:
			if (event.getAction() == MotionEvent.ACTION_UP){
				if (notification_like == 0) {
					notification_like = 1;
					btnSettingsLike.setImageResource(R.drawable.on);
				} else {
					notification_like = 0;
					btnSettingsLike.setImageResource(R.drawable.off);
				}
			}
			
			break;
		case R.id.btn_save_all:
			if (event.getAction() == MotionEvent.ACTION_UP){
				KeyboardHelper.hideSoftKeyboard(ChinhsuaThongtinActivity.this);
				progressDialog = ProgressDialog.show(ChinhsuaThongtinActivity.this, "", "Đang cập nhật...");
				mHandler.postDelayed(new Runnable() {

					@Override
					public void run() {
						if (null != progressDialog && progressDialog.isShowing())
							progressDialog.dismiss();
					}
				}, 90000);
				
				checkUpdateInfoTrue();
			}
			break;
		case R.id.edt_ten:
			if (event.getAction() == MotionEvent.ACTION_UP){
			}
			break;
		case R.id.edt_ngaysinh:
			if (event.getAction() == MotionEvent.ACTION_UP){
				showDialog(DATE_DIALOG_ID);
			}
			break;
		case R.id.edt_gioitinh:
			if (event.getAction() == MotionEvent.ACTION_UP){
				chooseGender();
			}
			break;
		case R.id.edt_thanhpho:
			if (event.getAction() == MotionEvent.ACTION_UP){
				showDialogThanhpho();
			}
			break;
		case R.id.edt_gioithieu_banthan:
			if (event.getAction() == MotionEvent.ACTION_UP){
			}
			break;
		case R.id.edt_email:
			if (event.getAction() == MotionEvent.ACTION_UP){
				showDialofArlertDontEditEmail();
			}
			break;
		case R.id.btn_back:
			if(isProcessing == false) {
				closeActivity();
			} else {
				showDialogProcess();
			}
			break;
		default:
			break;
		}
		return false;
	}
	
	
	
}
